package cn.szzsi.common.model;

import cn.szzsi.common.model.base.BaseAdmanage;
import com.jfinal.kit.StrKit;

import java.util.Date;
import java.util.List;

/**
 * Created by yuanzheng on 2016/11/30.
 */

//@TableBind(tableName = "mall_admanage",pkName = "id")
public class Admanage extends BaseAdmanage<Admanage> {
    public static final Admanage dao=new Admanage().dao();

    /**
     * 根据广告类别id查询广告类别
     * @param
     * @return
     */
    public Adtype getByAdTypeId(){
        return Adtype.dao.findById(getInt("adTypeId"));

    }

    public void init(){
        Integer adTypeId = this.getInt("adTypeId");
        Adtype at = Adtype.dao.findById(adTypeId);
        this.put("typeName",at == null?"":at.getStr("name"));
    }

    public static final void saveAdManage(String adTypeId, String title, String image, String url, String uid){
        Admanage adManage=new Admanage();
        adManage.set("adTypeId",adTypeId);
        adManage.set("title",title);
        adManage.set("image",image);
        adManage.set("url",url);
        adManage.set("uid",uid);
        adManage.set("createDate",new Date());
        adManage.save();

    }

    public static final void updateAdManage(Admanage adManage, String adTypeId, String title, String image, String url){
        adManage.set("adTypeId",adTypeId);
        adManage.set("title",title);
        if(StrKit.notBlank(image)){
            adManage.set("image",image);
        }
        adManage.set("url",url);
        adManage.update();

    }

    public List<Admanage> getAdImageByUid(String uid){
        return dao.find("select * from mall_admanage where uid=? ",uid);
    }

    public List<Admanage>getByUidAndAdTypeId(String shopId,Integer adTypeId){
        return dao.find("select * from mall_admanage where uid=? and adTypeId=?",shopId,adTypeId);

    }
}
